home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / bbskt30a.zip / MTASK20.ZIP / TEST1.PAS < prev   
Pascal/Delphi Source File  |  1990-03-12  |  2KB  |  76 lines

  1. PROGRAM test1;
  2.  
  3. {Demonstration program for MTASK 2.0, a simple multi-tasker unit for
  4. Turbo Pascal 5.
  5.  
  6. Written in November, 1988, and donated to the public domain by:
  7.  
  8.    Wayne E. Conrad
  9.    2627 North 51st Ave, #219
  10.    Phoenix, AZ  85035
  11.    BBS: (602) 484-9356, 300/1200/2400, 24 hours/day
  12. }
  13.  
  14.  
  15.  
  16. {$F+} {All tasks must be FAR}
  17.  
  18.  
  19. USES
  20.   mtask;
  21.  
  22.  
  23. {This task is created more than once, so the same code is executed for
  24. multiple tasks.  Since each task has its own stack, each task's local
  25. variables are unique to that task.  Global variables, however, are
  26. shared between tasks.}
  27.  
  28. PROCEDURE sub_task (VAR p);
  29. VAR
  30.   i        : Integer;
  31.   my_id    : Word;
  32.   parent_id: Word ABSOLUTE p;
  33. BEGIN
  34.   my_id := current_task_id;
  35.   Writeln ('Task ', my_id, ' started by task ', parent_id);
  36.   FOR i := 1 TO 4 DO
  37.     BEGIN
  38.     Writeln ('task ', my_id, ': i = ', i);
  39.     switch_task;
  40.     END;
  41.   Writeln ('Task ', my_id, ' terminating');
  42. END;
  43.  
  44.  
  45.  
  46. {Create a couple of tasks, all doing the same thing (counting & displaying
  47. what they're doing).  Wait for all the tasks to exit before we exit.}
  48.  
  49. CONST
  50.   tasks_to_create = 2;
  51.  
  52. VAR
  53.   child_id: Word;
  54.   my_id : Word;
  55.   result  : Word;
  56.   i       : Word;
  57.  
  58. BEGIN
  59.   Writeln;
  60.   Writeln;
  61.   Writeln ('MaxAvail = ', MaxAvail, '  MemAvail = ', MemAvail);
  62.   my_id := current_task_id;
  63.   FOR i := 1 TO tasks_to_create DO
  64.     BEGIN
  65.     create_task (sub_task, my_id, 1024, child_id, result);
  66.     Writeln ('Task ', my_id, ' created task ', child_id,
  67.      ' with result ', result);
  68.     END;
  69.   REPEAT
  70.     Writeln ('Task ', my_id, ' waiting for other tasks to finish');
  71.     switch_task;
  72.   UNTIL number_of_tasks = 1;
  73.   Writeln ('MaxAvail = ', MaxAvail, '  MemAvail = ', MemAvail);
  74.   Writeln ('Task ', my_id, ' exiting')
  75. END.
  76.